package using.supers;
import java.sql.*;

public class SQL_sever {
    static Connection con = null;
    static Statement sql = null;
    static ResultSet res = null;

    public SQL_sever() {
    }

    public static Connection connection() {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            System.out.println("数据库驱动加载成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:sqlserver://localhost:1433;DatabaseName=mian";
        String username = "sa";
        String passward = "123456";
        try {
            con = DriverManager.getConnection(url, username, passward);
            System.out.println("数据库连接成功");
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        return con;
    }

    // 测试连接
    public static void main(String[] args) {
        SQL_sever  a = new SQL_sever ();
        a.connection();
    }
}

